package com.offcn.controller;

import com.offcn.bean.Btype;
import com.offcn.service.BtypeService;
import com.offcn.utils.OAResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/btype")
public class BtypeController {

    @Autowired
    private BtypeService btypeService;

    @RequestMapping("/{page}")
    public String forwardPage(@PathVariable("page") String page, Integer typeid, Model model){
        model.addAttribute("typeid",typeid);

        return "btype/"+page;
    }


    @RequestMapping("/getBigCategory")
    @ResponseBody
    public List<Btype> getBigCategory(){
        return btypeService.getBigCategory();
    }


    @RequestMapping("/getSmallCategory")
    @ResponseBody
    public List<Btype> getSmallCategory(int typeid){
        return btypeService.getSmallCategory(typeid);
    }

    @RequestMapping("/saveBtype")
    @ResponseBody
    public OAResult saveBtype(Btype btype){
        return btypeService.saveBtype(btype);
    }

    @RequestMapping("/saveBtypeSmall")
    @ResponseBody
    public OAResult saveBtypeSmall(Btype btype, HttpSession session){
        return btypeService.saveBtypeSmall(btype,session);
    }

    @RequestMapping("/deleteBtype")
    @ResponseBody
    public OAResult deleteBtype(int typeid){
        return btypeService.deleteBtype(typeid);
    }

    @RequestMapping("/deleteBtypeBig")
    @ResponseBody
    public OAResult deleteBtypeBig(int typeid){
        return btypeService.deleteBtypeBig(typeid);
    }


    @RequestMapping("/getBtypeById")
    @ResponseBody
    public Btype getBtypeById(int typeid){
        return btypeService.getBtypeById(typeid);
    }

    @RequestMapping("/updateBtype")
    @ResponseBody
    public OAResult updateBtype(Btype btype){
        return btypeService.updateBtype(btype);
    }
}
